home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / SAT 2.3b4 / Demo ƒ / Collision][ demo ƒ / Collision][.p < prev    next >
Text File  |  1995-01-27  |  2KB  |  64 lines

  1. {******************************}
  2. {********* SAT Collision ][ **********}
  3. {******************************}
  4.  
  5. {A more advanced version of SAT Collision, demonstrating the use of callback routines}
  6. {(hit task) for collision handling. What has happened is that the apples switch between}
  7. {good and bad, and we are not supposed to eat it when it's bad.}
  8.  
  9. program SATcollisionII;
  10.  
  11.     uses
  12. {$ifc UNDEFINED THINK_PASCAL}
  13.         Types, QuickDraw, Menus, Windows, TextEdit, Fonts, Dialogs, Memory, {OSEvents,{}
  14. {$endc}
  15.         SAT, sMrEgghead, sApple;
  16.  
  17.     var
  18.         ignoreSp: SpritePtr;
  19.         l: longint;
  20.         ignore: integer;
  21.         p: Point;
  22. begin
  23. {Standard Inits are done by Think Pascal.}
  24. {$ifc UNDEFINED THINK_PASCAL}
  25.     InitGraf(@qd.thePort);
  26.     InitFonts;
  27.     InitWindows;
  28. {InitMenus;}
  29. {TEInit;}
  30.     InitDialogs(nil);
  31.     MaxApplZone;
  32. {$endc}
  33.  
  34. {We configure for kBackwardCollision. We can't use kKindCollision here, since we want "friends"}
  35. {to hit each other as well as "enemies".}
  36.     SATConfigure(true, kVPositionSort, kBackwardCollision, 32);
  37.  
  38.     SATInit(128, 129, 512, 322);
  39.  
  40.     InitMrEgghead;
  41.     InitApple;
  42.  
  43.     GetMouse(p);
  44.     ignoreSp := SATNewSprite(0, p.h, p.v, @SetupMrEgghead);
  45.     ignoreSp := SATNewSprite(0, 0, SATRand(gSAT.offSizeV - 32), @SetupApple);
  46.  
  47.     HideCursor;
  48.  
  49. {Optional init for better sound. Get two channels if possible, since we use fairy long sounds.}
  50.     ignore := SATSoundInitChannels(2);
  51.  
  52.     repeat
  53.         l := TickCount;
  54.         SATRun(true);
  55. {Start a new sprite once in a while.}
  56.         if SATRand(40) = 1 then
  57.             ignoreSp := SATNewSprite(0, 0, SATRand(gSAT.offSizeV - 32), @SetupApple);
  58.         while l > TickCount - 2 do {Maximize speed to 30 fps}
  59.             ;
  60.     until Button;
  61.     ShowCursor;
  62.     FlushEvents(mDownMask, 0); {Flush the mouse click, so we won't click randomly in the Finder!}
  63.     SATSoundShutUp; {Always make sure the sound channel is de-allocated!}
  64. end.